//
//  RSPlayerData.m
//  ReplayStar
//
//  Created by Félix Cloutier on 11-11-02.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "RSPlayerData.h"

NSString* kRPPlayerProtossRace = @"Protoss";
NSString* kRPPlayerTerranRace = @"Terran";
NSString* kRPPlayerZergRace = @"Zerg";
NSString* kRPPlayerRandomRace = @"Random";
NSString* kRPPlayerUnknownRace = @"Unknown";

RSReplayColor RSReplayColorCreate(unsigned char r, unsigned char g, unsigned char b)
{
	RSReplayColor color;
	color.r = r;
	color.g = g;
	color.b = b;
	return color;
}

@implementation RSPlayerData

@synthesize uid;
@synthesize name;
@synthesize color;
@synthesize isWinner;
@synthesize handicap;
@synthesize difficulty;
@synthesize region;

-(NSString*)race
{
	return race;
}

-(void)setRace:(NSString *)value
{
	if ([value isEqualToString:kRPPlayerProtossRace])
		race = kRPPlayerProtossRace;
	else if ([value isEqualToString:kRPPlayerTerranRace])
		race = kRPPlayerTerranRace;
	else if ([value isEqualToString:kRPPlayerZergRace])
		race = kRPPlayerZergRace;
	else if ([value isEqualToString:kRPPlayerRandomRace])
		race = kRPPlayerRandomRace;
	else
	{
		assert(!"Unknown race");
		race = kRPPlayerUnknownRace;
	}
}

-(BOOL)isComputer
{
	return uid == 0;
}

-(NSString*)description
{
	return [NSString stringWithFormat:@"%@ (%@, %@) #%02hhx%02hhx%02hhx",
			name,
			self.isComputer ? @"Computer" : @"Human",
			race,
			color.r, color.g, color.b];
}

-(void)dealloc
{
	self.name = nil;
	[super dealloc];
}

@end
